import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { EquipsPanel } from "../player/equip/EquipsPanel";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ResFileConst } from "../../resource/ResFileConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ECountryPosition } from "../../../../Message/Game/ECountryPosition";
import { ESex } from "../../../../Message/Public/ESex";
import { Cache } from "../../cache/Cache";
import { CountryConfig } from "../../resource/CountryConfig";
import { StatueUserPlayer } from "../../scene/player/entity/StatueUserPlayer";
import { DirectionType } from "../../scene/modle/data/DirectionType";
import { SPlayerItemUpdate } from "../../../../Message/Game/SPlayerItemUpdate";
import { ItemData } from "../../resource/info/ItemData";
import { SecondCareerUtil } from "../secondCareer/util/SecondCareerUtil";
import { UserEquipmentUtil } from "../range/userEquip/UserEquipmentUtil";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GTextArea } from "../../../../com/mui/controls/GTextArea";
type int = number;
//class CountryPositionMemberPanel
    
    export  class CountryPositionMemberPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 667, 403, this);
            ObjCreate.createBg(6, 55, 395, 185, this);
            ObjCreate.createBg(6, 248, 395, 150, this);
            ObjCreate.createBg(6, 52, 397, 35, this, ImagesConst.RbListHeader);
            ObjCreate.createBg(6, 245, 397, 35, this, ImagesConst.RbListHeader);
            ObjCreate.createBg(3, 5, 660, 45, this, ImagesConst.positionBg);
            ObjCreate.createGImageBitmap(ImagesConst.countryPosEquipBg, 406, 90, this);
            this._equipsPanel = new EquipsPanel();
            this._equipsPanel.x = 410;
            this._equipsPanel.y = 79;
            this._equipsPanel.setAddPanelVisible(false);
            addChild(this._equipsPanel);
            this._positionBmp = new Object /* flash.display.Bitmap */();
            this._positionBmp.x = 10;
            this._positionBmp.y = 12;
            addChild(this._positionBmp);
            this._posTitle1 = new Object /* flash.display.Bitmap */();
            this._posTitle1.x = 165;
            this._posTitle1.y = 60;
            addChild(this._posTitle1);
            this._posTitle2 = new Object /* flash.display.Bitmap */();
            this._posTitle2.x = 165;
            this._posTitle2.y = 252;
            addChild(this._posTitle2);
            this._posNameBmp = new Object /* flash.display.Bitmap */();
            this._posNameBmp.x = 405;
            this._posNameBmp.y = 57;
            addChild(this._posNameBmp);
            this._privilegeDes = ObjCreate.createTextArea("", 15, 85, 385, 155, this);
            this._positionDes = ObjCreate.createGTextField("", 15, 280, 390, 120, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 3));
            this._positionDes.wordWrap = true;
            this._positionDes.multiline = true;
            ObjCreate.createGImageBitmap(ImagesConst.FightingStrgLabel, 490, 60, this);
            ObjCreate.createBg(560, 57, 100, 24, this, ImagesConst.SelectedBg);
            ObjCreate.createGLoadedButton(ResFileConst.FightingIcon, 570, 60, 19, 18, this);
            this._fightStrengthTxt = ObjCreate.createGTextField("--", 590, 59, 60, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._fightStrengthTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._playerName = ObjCreate.createGTextField("", 410, 95, 253, 20, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6));
            this._rTabBar = new GTabBar();
            this._rTabBar.buttonStyleName = "ButtonMini";
            this._rTabBar.buttonWidth = 71;
            this._rTabBar.x = 60;
            this._rTabBar.y = 10;
            this._rTabBar.horizontalGap = 3;
            this._rTabBar.buttonFilters = [FilterConst.glowFilter];
            this._rTabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onTabBarSelectedHandler);
            this._rTabBar.selectedIndex = 0;
            addChild(this._rTabBar);
            this.updateTabDataProvider();
            this.onTabBarSelectedHandler();
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._positionBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.cPosition);
            this._posTitle1.bitmapData = GlobalClass.getBitmapData(ImagesConst.cPositionTitle_1);
            this._posTitle2.bitmapData = GlobalClass.getBitmapData(ImagesConst.cPositionTitle_2);
            if (this._position == ECountryPosition._ECountryPositionKing || this._position == ECountryPosition._ECountryPositionQueen) 
            {
                if (this._kingSex != ESex._ESexMan) 
                {
                    this._posNameBmp.bitmapData = GlobalClass.getBitmapData("cPositionEx_" + this._position);
                }
                else 
                {
                    this._posNameBmp.bitmapData = GlobalClass.getBitmapData("cPosition_" + this._position);
                }
            }
            else 
            {
                this._posNameBmp.bitmapData = GlobalClass.getBitmapData("cPosition_" + this._position);
            }
            return;
        }

        /* internal  */updateTabDataProvider(): void
        {
            var loc1=Cache.instance.country.kingSex;
            var loc2=CountryConfig.instance.getCountryTabDataProvider(loc1);
            this._rTabBar.dataProvider = loc2;
            return;
        }

        /* internal  */addUserModel(arg1: int, arg2: int, arg3: int, arg4: Map<any, any> /* flash.utils.Dictionary */, arg5: int=0, arg6: int=0): void
        {
            if (this._userModel != null) 
            {
                this._userModel.dispose(false);
            }
            else 
            {
                this._userModel = new StatueUserPlayer();
            }
            this._userModel.direction = DirectionType.South;
            this._userModel.camp = arg1;
            this._userModel.sex = arg2;
            this._userModel.career = arg3;
            this._userModel.reserveJs.weaponStPerLv = arg5;
            this._userModel.reserveJs.wingStrPerLv = arg6;
            this._userModel.updateEquipByDic(arg4);
            this._userModel.wxPlayerShow();
            this._userModel.x = 535;
            this._userModel.y = 290;
            addChild(this._userModel);
            return;
        }

        /* internal  */onTabBarSelectedHandler(arg1: MuiEvent=null): void
        {
            var loc8=null;
            var loc9=0;
            var loc10=0;
            var loc11=null;
            var loc12=null;
            var loc13=null;
            this.resetPanel();
            this._kingSex = Cache.instance.country.kingSex;
            var loc1=this._rTabBar.selectedItem;
            var loc2=loc1.name as int;
            this._position = loc2;
            var loc3=Cache.instance.country.getOfficerInfoByPosition(loc2);
            var loc4=[];
            var loc5=[];
            var loc6=0;
            if (loc3) 
            {
                this._fightStrengthTxt.htmlText = loc3.fight + "";
                this._playerName.htmlText = loc3.player.name;
                loc9 = (loc8 = loc3.playerItemUpdates).length;
                loc10 = Cache.instance.pack.rolePackCache.sbag.capacity;
                loc6 = 0;
                while (loc6 < loc10) 
                {
                    loc4.push(null);
                    loc5.push(null);
                    ++loc6;
                }
                loc6 = 0;
                while (loc6 < loc9) 
                {
                    if ((loc12 = loc8[loc6] as SPlayerItemUpdate).playerItem) 
                    {
                        loc13 = new ItemData(loc12.playerItem);
                        loc4[(loc12.posIndex - 1)] = loc13;
                        if (loc3.secondCareer != 0) 
                        {
                            loc5[(loc12.posIndex - 1)] = SecondCareerUtil.getSecondCareerItemData(loc3.player.career, loc3.secondCareer, loc13);
                        }
                    }
                    ++loc6;
                }
                this._equipsPanel.setEquipments(loc4);
                loc11 = UserEquipmentUtil.getUserEquipmentData(loc4, loc3.fashionState, loc3.wingState, loc3.fashionWeaponState, false, false, false);
                this.addUserModel(loc3.player.camp, loc3.player.sex, loc3.player.career, loc11.equipDic, loc11.weaponStPerLv, loc11.wingStLv);
            }
            else 
            {
                loc6 = 0;
                while (loc6 < Cache.instance.pack.rolePackCache.sbag.capacity) 
                {
                    loc4.push(null);
                    loc5.push(null);
                    ++loc6;
                }
                this._equipsPanel.setEquipments(loc4);
                if (this._userModel && this._userModel.parent) 
                {
                    removeChild(this._userModel);
                }
            }
            LoaderHelp.addResCallBack(ResFileConst.countryPosition, this.onResLoaded);
            var loc7;
            if (loc7 = loc1.info) 
            {
                this._positionDes.htmlText = loc7.positionDes;
                this._privilegeDes.htmlText = loc7.privilegeDes;
            }
            return;
        }

        /* internal  */resetPanel(): void
        {
            this._fightStrengthTxt.htmlText = "--";
            this._playerName.htmlText = "";
            this._positionDes.htmlText = "";
            this._privilegeDes.htmlText = "";
            return;
        }

        /* internal */ /* var */_rTabBar: GTabBar;

        /* internal */ /* var */_equipsPanel: EquipsPanel;

        /* internal */ /* var */_positionBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_posTitle1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_posTitle2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_posNameBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_positionDes: GTextFiled;

        /* internal */ /* var */_privilegeDes: GTextArea;

        /* internal */ /* var */_position: int;

        /* internal */ /* var */_kingSex: int;

        /* internal */ /* var */_fightStrengthTxt: GTextFiled;

        /* internal */ /* var */_playerName: GTextFiled;

        /* internal */ /* var */_userModel: StatueUserPlayer;
    }
